/*
 * Copyright (c)  2015~2020, xforceplus
 * All rights reserved.
 * Project:datacare-orm
 * Id: Manager.java   2020-10-07 20-12-04
 * Author: Evan
 */
package cn.datacare.orm.manager;

import cn.datacare.orm.connection.ConnectionSource;
import cn.datacare.orm.conversion.NameConversion;
import cn.datacare.orm.dialect.Dialect;
import cn.datacare.orm.engine.Beetl;
import cn.datacare.orm.interceptor.Interceptor;
import cn.datacare.orm.interceptor.InterceptorContext;
import cn.datacare.orm.loader.SQLLoader;
import cn.datacare.orm.manager.impl.MetaDataManager;
import cn.datacare.orm.mapping.BeanProcessor;
import cn.datacare.orm.query.PageQuery;
import cn.datacare.orm.source.*;
import org.beetl.core.Context;

import java.util.Map;

/**
 * <p>
 * Title: Manager
 * </p>
 * <p>
 * Description: Manager (Entity)
 * </p>
 * <p>
 * Copyright: 2015~2020
 * </p>
 * <p>
 * Company/Department: xforceplus
 * </p>
 *
 * @author Evan
 * <b>Creation Time:</b> 2020-10-07 20-12-04
 * @since V1.0
 */
public interface Manager extends CurdSqlManager{
    /**
     * 获取数据库方言
     * @return dialect Dialect
     */
    Dialect getDialectType();

    /**
     * 获取默认Schema
     *
     * @return String defaultSchema
     */
    String getDefaultSchema();

    /**
     * 获取连接
     * @return ConnectionSource
     */
    ConnectionSource getConnectionSource();

    /**
     * 分页查询
     *
     * @param sqlId      ID
     * @param resultType Class
     * @param query      query
     */
    void pageQuery(String sqlId, Class resultType, PageQuery query);

    /**
     * 获取Beetl模板引擎
     * @return Beetl
     */
    Beetl getBeetl();






    /**
     * 执行 executeOnConnection
     * @param onConnection OnConnection<T>
     * @return T
     */
    <T> T executeOnConnection(OnConnection<T> onConnection);



    /***
     * 单行选择
     * @param sqlId
     * @param map
     * @param resultType
     * @return Object
     */
    Object selectSingle(String sqlId, Map map, Class resultType);

    /**
     * 查询
     * @param sqlId
     * @param returnType
     * @param map
     * @param offset
     * @param size
     * @return Object
     */
    Object select(String sqlId, Class returnType, Map map, long offset, long size);





    /***
     * 获取分页SqlScript
     * @param sqlId sqlId
     * @return
     */
    SQLScript getPageSqlScript(String sqlId);

    /**
     * 获取数据
     * @param clazz
     * @return Object
     */
    Object allCount(Class clazz);



    /**
     * 更新消息
     *
     * @param arg
     * @return int
     */
    @Override
    int upsertByTemplate(Object arg);

    /**
     * @param arg
     * @return
     */
    @Override
    int upsert(Object arg);



    /**
     * @param algorithm
     * @param param
     * @param name
     * @return
     */
    Object getAssignIdByIdAutoGen(String algorithm, String param, String name);

    /**
     * 获取SQLResult
     *
     * @param s
     * @param inputParas
     * @param ctx
     * @return SQLResult
     */
    SQLResult getSQLResult(String s, Map inputParas, Context ctx);



    /***
     *  SQLScript
     * @param sqlId
     * @return SQLScript
     */
    SQLScript getScript(String sqlId);

    /***
     *
     * @param targetEntity
     * @param key
     * @return
     */
    boolean exist(Class targetEntity, Object key);

    /***
     * 更新指定表
     * @param clazz Class
     * @param param 参数
     * @return 更新行数
     */
    @Override
    int updateAll(Class<?> clazz, Object param);

    /***
     * ClassLoader
     * @return ClassLoader
     */
    ClassLoader getEntityLoader();

    /**
     * 获取
     *
     * @return
     */
    SQLLoader getSqlLoader();

    /**
     * NameConversion
     *
     * @return
     */
    NameConversion getNameConversion();

    /**
     * 获取MetaDataManager
     *
     * @return MetaDataManager
     */
    MetaDataManager getMetaDataManager();

    /**
     *
     * @return
     */
    String getSQLManagerName();

    /**
     * 获取拦截器
     * @return
     */
    Interceptor[] getInters();

    /**
     *  BeanProcessor
     * @return BeanProcessor
     */
    BeanProcessor getDefaultBeanProcessors();

    /**
     *  InterceptorContext
     * @return InterceptorContext
     */
    Map<String, BeanProcessor> getProcessors();
}
